package com.ruoyi.project.system.task.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.task.domain.Task;
import com.ruoyi.project.system.task.service.TaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/task/grant")
public class GrantController extends BaseController {

    private String prefix = "system/task/grant";

    @Autowired
    private TaskService taskService;

    /**
     * 跳转到下发任务
     * @return
     */
    @RequiresPermissions("system:grant:view")
    @GetMapping()
    public String grant()
    {
        return prefix + "/grant";
    }

    /**
     * 更具条件分页查询
     * @param task 条件
     * @return
     */
    @RequiresPermissions("system:grant:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Task task)
    {
        startPage();
        List<Task> list = taskService.selectGrantList(task);
        return getDataTable(list);
    }

    /**
     * 根据任务id查找下发的任务
     * @param taskId 任务id
     * @param mmap 回显的数据
     * @return
     */
    @RequiresPermissions("system:grant:show")
    @GetMapping("/show/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap)
    {
        mmap.put("task", taskService.selectGrantById(taskId));
        return prefix + "/edit";
    }

}
